package cn.tedu.controller;

import cn.tedu.pojo.Collect;
import cn.tedu.pojo.Novel;
import cn.tedu.service.RemoteService;
import cn.tedu.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/collect")
public class CollectController {
    @Autowired
    private RemoteService remoteService;

    //添加收藏
    @PutMapping("/addNovel")
    public SysResult addNovel(@RequestBody Collect collect){
        remoteService.addNovel(collect);
        return SysResult.success();
    }

    //移除收藏
    //feign不支持get、delete用对象传递
    @DeleteMapping("/deleteNovel")
    public SysResult deleteNovel(@RequestParam("userId") String userId,
                                 @RequestParam("novelId") String novelId){
        remoteService.deleteNovel(userId,novelId);
        return SysResult.success();
    }

    //查看所有收藏书籍
    @GetMapping("/getNovelByUserId")
    public SysResult getNovelByUserId(@RequestParam("userId") Integer userId){
        List<Novel> novels = remoteService.getNovelByUserId(userId);
        return SysResult.success(novels);
    }
}
